Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(material/button): combine MatButton and MatAnchor #30492

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Feb 14, 2025

Currently we have two directives for each button variant: MatButton which applies to button elements and MatButtonAnchor which applies to anchors.

This is problematic in a couple of ways:

  1. The styles, which can be non-trivial, are duplicated if both classes are used.
  2. Users have to think about which class they're importing.

These changes combine the two classes to resolve the issues and simplify our setup.

BREAKING CHANGE:
tabindex values set as [attr.tabindex] set on a Material button might not work as expected. Use tabindex for static values, or [tabindex]/[tabIndex] for dynamic ones.

@crisbeto crisbeto added the target: minor This PR is targeted for the next minor release label Feb 14, 2025
@crisbeto crisbeto requested a review from a team as a code owner February 14, 2025 08:47
@crisbeto crisbeto requested review from mmalerba and andrewseguin and removed request for a team February 14, 2025 08:47
@crisbeto crisbeto force-pushed the combined-buttons branch 5 times, most recently from e1f2211 to 074ed69 Compare February 18, 2025 08:54
@@ -153,14 +162,28 @@ export class MatButtonBase implements AfterViewInit, OnDestroy {
@Input({transform: booleanAttribute})
disabledInteractive: boolean;

/** Tab index for the button. */
@Input({transform: transformTabIndex})
tabIndex: number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be the deprecated one instead? I think most of our components that take a tabindex use the all-lowercase spelling

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we use tabIndex across a bunch of other components as well. I think it's because the native property is also called tabIndex, see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/tabIndex

const classList = (element as HTMLElement).classList;

this._isAnchor = element.tagName === 'A';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably should .toUpperCase() this to be safe

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be guaranteed to be uppercase. The only time tag names preserve their case is in SVG.

Currently we have two directives for each button variant: `MatButton` which applies to `button` elements and `MatButtonAnchor` which applies to anchors.

This is problematic in a couple of ways:
1. The styles, which can be non-trivial, are duplicated if both classes are used.
2. Users have to think about which class they're importing.

These changes combine the two classes to resolve the issues and simplify our setup.

BREAKING CHANGE:
`tabindex` values set as `[attr.tabindex]` set on a Material button might not work as expected. Use `tabindex` for static values, or `[tabindex]`/`[tabIndex]` for dynamic ones.
@angular-robot angular-robot bot added the detected: breaking change PR contains a commit with a breaking change label Feb 19, 2025
@crisbeto crisbeto added target: major This PR is targeted for the next major release and removed target: minor This PR is targeted for the next minor release labels Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: material/button detected: breaking change PR contains a commit with a breaking change target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants